package com.eddie.factory.simplefactory.pizzastore.order;
import com.eddie.factory.simplefactory.pizzastore.pizza.Pizza;
import lombok.SneakyThrows;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author Eddie
 * @date 2022/4/29 11:24
 */
public class OrderPizza {
    private SimpleFactory simpleFactory;
    public OrderPizza(SimpleFactory simpleFactory) {
     setSimpleFactory(simpleFactory);
    }

    public void setSimpleFactory(SimpleFactory simpleFactory) {
        //用户输入的
        String orderType;
        Pizza pizza;
        this.simpleFactory = simpleFactory;
        do {
            orderType = getType();
            pizza = simpleFactory.createPizza(orderType);
            if (pizza == null) {
                break;
            } else {
                pizza.bake();
                pizza.cut();
                pizza.box();
            }
        }while (true);
    }

    /**
     * 获取客户希望订购的披萨种类
     */
    @SneakyThrows
    private String getType() {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("input pizza type:");
        return bufferedReader.readLine();
    }

}
